<template>
	<view class="myCar">
		<view class="myCar-top">
			<!-- 顶部内容可以在这里添加 -->
		</view>
		
		<view class="myCar-bon" v-if="cars.length > 0">
			<view v-for="car in cars" :key="car.id">
				<view class="myCar-list">
					<view class="myCar-t">
						<view class="myCar-t-l">
							<image :src="car.imageUrl" class="myCar-t-img" />
						</view>
						<view class="myCar-t-r">
							<view class="myCar-t-r-view1">车型：{{ car.model }}</view>
							<view>车牌：{{ car.licensePlate }}</view>
						</view>
					</view>
					<view class="myCar-b">
						<image :src="car.isDefault ? '/static/my/默认 (1).png' : '/static/my/默认.png'" class="myCar-t-img1" />
						<view @click="setDefaultCar(car.id)" class="myCar-t-text">设为默认车辆</view>
						<view class="myCar-t-text2">删除</view>
					</view>
				</view>
			</view>
		</view>
		<view v-else class="no-data">
			<image src="/static/my/组 4.png" />
			<view>暂无车辆信息</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cars: [], // 初始化为空数组
				selectedCarId: null, // 存储选中的车辆ID
			}
		},
		mounted() {
			// 组件挂载后填充车辆数据
			this.fetchCars(); // 假设你有一个方法来获取车辆数据
		},
		methods: {
			fetchCars() {
				// 模拟获取车辆数据
				this.cars = [
					{ id: 1, model: '奔驰-GR', licensePlate: '豫M5468', imageUrl: '', isDefault: true },
					{ id: 2, model: '宝马-X5', licensePlate: '豫M5469', imageUrl: '', isDefault: false },
					{ id: 3, model: '奥迪-Q7', licensePlate: '豫M5470', imageUrl: '', isDefault: false },
					{ id: 4, model: '特斯拉-Model S', licensePlate: '豫M5471', imageUrl: '', isDefault: false },
					{ id: 5, model: '丰田-Camry', licensePlate: '豫M5472', imageUrl: '', isDefault: false },
				]; // 这里模拟填充数据
			},
			setDefaultCar(carId) {
				// 设置选中的车辆的isDefault为true
				this.cars.forEach(car => {
					car.isDefault = (car.id === carId);
				});
			}
		}
	}
</script>

<style>
	.myCar {
		position: relative;
	}
	.myCar-top {
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		background-color: #297BF6;
		height: 300rpx;
		color: aliceblue;
	}
	.myCar-bon {
		position: absolute;
		width: 93%;
		top: 40rpx;
		left: 30rpx;
		background-color: transparent;
		margin: 0 auto;
		border-radius: 25rpx;
	}
	.myCar-list {
		margin: 20rpx;
		border-radius: 25rpx;
		background-color: #fff;
		height: 250rpx;
		color: #000;
		padding: 20rpx 30rpx;
	}
	.myCar-t {
		border-bottom: #b7b7b7 solid 1rpx;
		height: 130rpx;
	}
	.myCar-t-img {
		width: 120rpx;
		height: 120rpx;
		float: left;
	}
	.myCar-t-img1 {
		width: 50rpx;
		height: 50rpx;
		float: left;
		margin-top: 40rpx;
	}
	.myCar-t-text {
		float: left;
		margin-top: 45rpx;
	}
	.myCar-t-text2 {
		float: right;
		margin-top: 45rpx;
	}
	.myCar-t-r-view1 {
		margin-bottom: 20rpx;
	}
	.myCar-t-r {
		margin-top: 30rpx;
		height: 100rpx;
	}
	.no-data {
		text-align: center;
		margin-top: 50rpx;
	}
</style>